<?php
namespace Live\Controller;
use Think\Controller;

class PublicController extends Controller {  
    /**
     * 后台登录
     * @return [type] [description]
     */
    public function login(){
    	if(IS_POST) {
    		$adminModel = D("User");
    		if($adminModel->create()) {
    			$this->success('登录成功', U('Live/index'));
    			exit;
    		} else {
    			$this->error($adminModel->getError());
    		}
    	}

        $this->display();
    }

    /**
     * 后台退出
     * @return [type] [description]
     */
    public function logout() {
		session('liveadmin_uid', null);
		session('liveadmin_username', null);
		session('liveadmin_realname', null);
        session('is_admin', null);

        redirect(U('Public/login'));
    }


    public function liveThumbCallBack(){
        $res=I('post.');
        \Think\Log::record(json_encode($res),'七牛回调',true);
        echo true;
    }

    public function testMq(){
        for($i=0;$i<1;$i++){
        $body = '  
        {  
            "platform":"6",  
            "sign":"测试",  
            "mobile":"15820786542",  
            "content":"您好！您的验证码为122223",  
            "type":"1",  
            "callback":"http://jianwei.dev.appwuhan.net/Live/Public/testMq3"
        }';

        $obj = new \Common\Common\Mq();
        echo $obj->sendQueue($body);
        }
    }

    public function  testMq2(){
        $this->ajaxReturn(array('errcode'=>20000));

    }


    public function reSendMq(){
            $body = json_encode($_POST);
            $destination = I('get.destination');
            $obj = new \Common\Common\Mq();
            $obj->sendQueue($body,$destination);
        }

    public function clicksUpdate($page){
        $ch = curl_init();
        //设置选项，包括URL
        curl_setopt($ch, CURLOPT_URL, "http://plive.appwuhan.com/common/getLiveList.php?page={$page}&num=10");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        //执行并获取HTML文档内容
        $output = curl_exec($ch);
        //释放curl句柄
        curl_close($ch);
        //打印获得的数据
        $r=json_decode($output,true);


        if(count($r)>0){
            
            foreach($r as $v){
                    $res=M('Live')->where(array('group_id'=>$v['group_id']))->save(array('rand'=>$v['count']));
                    echo M()->_sql()."<br>";
            }
            
            
            $this->clicksUpdate($page+1);
        }

        
    }

}  